<?php

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

require_once __DIR__ . '/includes/init.php';
require_once __DIR__ . '/includes/logout_sess.php';

use sessions\AutoLogin;

if (isset($_POST['logout'],$_SESSION['remember']) || isset($_POST['logout'],$_SESSION['parsclick_auth'])) {

?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<center>
<form>
		<button type="submit" class="btn btn-default"> Log out on this device </button>
		<input type="hidden" name="single" value="single">
</form>
<br>
<form>

	<button type="submit" class="btn btn-default"> Log out on all devices</button>
		<input type="hidden" name="all" value="all">
</form>
<center>


<?php
} elseif (isset($_POST['single']) || isset($_POST['all'])) {
	$autologin = new AutoLogin($db);
	if (isset($_POST['single'])) {
		$autologin->logout(false);
	} else {
		$autologin->logout(true);
	}
	logout_sess();
	
} elseif (isset($_POST['logout'])) {
	logout_sess();
}

?>

<script type="text/javascript">
	
$("form").on("submit", function (e){
	postData = $(this).serialize();
	    $.ajax({
	    type: "POST",
	    data: postData,
	    url: "./logout.php",
	    success: function(data) {
	       $("#content").html(data);
	    },
	    error: function(xhr, status, error){
	      alert(xhr.responseText);
	    }
	  	});
  	e.preventDefault();
});

</script>
